home *** CD-ROM | disk | FTP | other *** search
- From: adamnash@cs.stanford.edu (Adam Nash)
- Message-ID: <adamnash-1303962301470001@gel.stanford.edu>
- X-Original-Date: 14 Mar 1996 07:02:58 GMT
- Path: in1.uu.net!bounce-back
- Date: 15 Mar 96 00:12:05 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Problem with new in templates...
- Organization: Computer Science, Stanford University
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMUi4E+EDnX0m9pzZAQHhzgF+I0aZTe0bM0trjhNWDfBgKfGVWj4zwKE+
- yIvGY0W4ore5GfNcokISH7pSMzQBQN/s
- =105S
-
- OK Problem Scenario:
-
- There is a templatized data structure that is based on type DATA. This
- data structure features a method that depends on a method in type DATA.
- Thus, for semantic reasons, the template assumes that DATA is a pointer
- type.
-
- So, here is the method:
-
- template <class DATA>
- void GIDTable::ReadFromStream(LStream *inStream)
- {
- DATA data;
-
- ...
-
- data = new DATA;
- (*data).ReadFromStream(inStream);
-
- ...
- }
-
-
- The problem occurs on the second line. data is of type DATA, so you
- really want to allocate a new (*DATA). IE, if DATA is a CBar *, then data
- is a CBar *,
- so we want it to say: data = new CBar;
-
- How can I do this, only knowing the pointer type?
- IE, is there a version of new that can take the pointer type, rather than
- the actual type? RTTI is fair game.
-
-
- Please Help, this is an actual problem!
-
- -Adam
-
- --
- Adam Nash
- CS 108 TA
- adamnash@cs.stanford.edu
- http://www-leland.stanford.edu/~smashman
- Stanford University - Computer Science
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-